package com.ctgu.j08.controller;

import com.ctgu.j08.service.DepartmentService;
import com.ctgu.j08.vo.DUser;
import com.ctgu.j08.vo.Department;
import com.ctgu.j08.vo.Result;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @version 1.0
 * @author: Saiya Wang
 * @date: 2021/5/28 20:58
 */
@Controller
@RequestMapping("/depart")
public class DepartController {
    @Resource
    private DepartmentService departmentService;

    @PostMapping("/addDepart")
    @ApiOperation("添加部门信息")
    @ResponseBody
    public Result addUser(@RequestBody Department department){
        System.out.println("添加的部门"+department);
        return departmentService.addDepartment(department);
    }

    @PutMapping("/edit")
    @ApiOperation("更新部门信息")
    @ResponseBody
    public Result editUser(@RequestBody Department department)
    {
        return departmentService.editDepart(department);
    }

    @DeleteMapping("/del/{departId}")
    @ApiOperation("根据部门id删除部门")
    @ResponseBody
    public Result delUserById(@PathVariable("departId") int departId){
        System.out.println("删除Controller");
        return departmentService.delDepartById(departId);
    }

    @GetMapping("/getAllDepartInfo")
    @ApiOperation("获取全部部门信息")
    @ResponseBody
    public Result getAllUserInfo()
    {
        return departmentService.getAllDepartInfo();
    }

    @GetMapping("/searchDepartInfo/{departName}")
    @ApiOperation("查询部门信息")
    @ResponseBody
    public Result searchUserInfo(@PathVariable("departName") String departName)
    {
        System.out.println("查询用户Controller");
        return departmentService.searchDepartByName(departName);
    }
}
